//服务端调用
const {stringify} = require('flatted')
const axios = require('axios');

async function getAccess_token() {
    try {
        const APPID = process.env.APPID;
        const APPSECRET = process.env.APPSECRET;
        const response = await axios.get(`https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${APPID}&secret=${APPSECRET}`); 
        process.env.ACCESS_TOKEN = response.data.access_token;
    } catch (error) {
        console.log("Testing error: " + error);
    }
}

async function getWxCodeUnlimit() {
    try {
        const data = {
            "scene": "barID=1&tableNum=2",
            "check_path": true,
            "env_version": "develop"
        }
        const response = await axios.post(`https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=${process.env.ACCESS_TOKEN}`,data);
    } catch (error) {
        console.log("getWxCodeUnlimit error: " + error);
    }
}

module.exports = {getAccess_token,getWxCodeUnlimit};